package com.youth.framework.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.springframework.util.DigestUtils;

public class DigestTest {
	
	
	public static void testDigestUtils()
	{
		System.out.println(DigestUtils.md5DigestAsHex("12345".getBytes()));
	}

	/**
	 * @param args
	 * @throws NoSuchAlgorithmException 
	 */
	public static void main(String[] args) throws NoSuchAlgorithmException {
		String sessionid = "12345";

		byte[] defaultBytes = sessionid.getBytes();
		MessageDigest algorithm = MessageDigest.getInstance("MD5");
		algorithm.reset();
		algorithm.update(defaultBytes);

		byte messageDigest[] = algorithm.digest();

		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < messageDigest.length; i++) {
			hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
		}
		String foo = messageDigest.toString();
		System.out.println("sessionid " + sessionid + " md5 version is "
				+ hexString.toString());
		
		testDigestUtils();
	}

}
